home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13334 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.infi.net!usenet
  2. From: Steve Rountree <srndtree@infi.net>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Skipping ahead in a file?
  5. Date: Sat, 06 Apr 1996 11:55:23 -0800
  6. Organization: InfiNet
  7. Message-ID: <3166CC2B.3F3E@infi.net>
  8. References: <4k17td$chn@news.csus.edu>
  9. NNTP-Posting-Host: h-agate.dc.infi.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win16; I)
  14.  
  15. Ralph A Pope wrote:
  16. > OK, basically what I want to do is take a file that's 20*(12+1)*4*4 bytes
  17. > long, and skip ahead 61 characters in the program several times.  Then I
  18. > want to be able to reset the file pointer to start 20 characters away
  19. > from the previous starting point.  I want to do this a total of 5 times.
  20. > Any idea of how to get this working?  I can't seem to figure out
  21. > fseek().  I'm using MS-DOS 6.2 with DJGPP, BTW.  Any help you can give me
  22. > would be GREATLY appreciated! :)
  23. > -Michael P.
  24.  
  25. try:
  26.  
  27.  FILE *info;  /* open as you need to, of course. */
  28.  long prev;
  29.  int dist=61; /* distance to move in file.  */
  30.  
  31.  prev=ftell(info);  /* set prev to current file pointer position. */
  32.  
  33.  fseek(info,dist,SEEK_CUR);  /* move file pointer a set distance (61) */
  34.  prev+=20;           /* assuming the 20 characters "away" is forward  */
  35.  fseek(info,prev,SEEK_SET);  /* establish file pointer 20 ahead of old 
  36.                              location */
  37.  
  38.  
  39.  Of course you will need to do standard checking for the EOF but, I think 
  40. this what you are "bascially" looking for. Good luck.
  41.  
  42. Steve Rountree
  43.